﻿@using Snow.AuthorityManagement.Core.Dto.Role
@model Snow.AuthorityManagement.Core.Dto.User.GetUserForEditOutput
<form asp-controller="User" asp-action="CreateOrEdit" id="modelForm" method="post" enctype="multipart/form-data"
      data-ajax="true" data-ajax-success="saveSuccess" data-ajax-failure="saveFailure">
    @Html.AntiForgeryToken()

    <div class="modal-body form-horizontal" id="modify">
        <div asp-validation-summary="ModelOnly" class="text-danger"></div>
        <input type="hidden" asp-for="User.ID" />

        <div class="form-group">
            <label asp-for="User.Name" class="control-label col-md-2"></label>
            <div class="col-md-10">
                <input asp-for="User.Name" class="form-control" placeholder="@Html.DisplayNameFor(model => model.User.Name)" />
                <span asp-validation-for="User.Name" class="text-danger"></span>
            </div>
        </div>

        <div class="form-group">
            <label asp-for="User.UserName" class="control-label col-md-2"></label>
            <div class="col-md-10">
                <input asp-for="User.UserName" class="form-control" placeholder="@Html.DisplayNameFor(model => model.User.UserName)" />
                <span asp-validation-for="User.UserName" class="text-danger"></span>
            </div>
        </div>

        <div class="form-group">
            <label asp-for="User.PhoneNumber" class="control-label col-md-2"></label>
            <div class="col-md-10">
                <input asp-for="User.PhoneNumber" class="form-control" placeholder="@Html.DisplayNameFor(model => model.User.PhoneNumber)" />
                <span asp-validation-for="User.PhoneNumber" class="text-danger"></span>
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-md-2">角色</label>
            <div class="col-md-10">
                <select id="Role" name="RoleIds[]" multiple="multiple">
                    @foreach (RoleSelectDto role in Model.Roles)
                    {
                        <option value="@role.Key" selected="@role.Selected">@role.Value</option>
                    }
                </select>
            </div>
        </div>
    </div>
</form>

<script type="text/javascript">
    $.validator.unobtrusive.parse('form');
    if ($('#Role').data('select2') !== undefined) {
        $('#Role').data('select2').destroy();
    }
    $('#Role').select2({
        language: "zh-CN",// 指定语言为中文，国际化才起效
        placeholder: '请选择',
        width: '100%',
        //data: modules
    });
</script>